#include"Udp_server.hpp"
#include"User.hpp"
int main(int argc, char* argv[])
{
    if(argc!= 2){
        std::cout<<"Usage: "<<argv[0]<<"[port]"<<std::endl;
        DIE(1);
    }
    uint16_t port = std::stoi(argv[1]);
    ENABLE_CONSOLE_LOG();
    //用户管理模块
    std::shared_ptr<UserManager> user_manager = std::make_shared<UserManager>();
    //网络模块
    std::unique_ptr<Udp_server> server = std::make_unique<Udp_server>(port);

    server->RegisterService([&user_manager](const InetAddr &id)->bool{return user_manager->AddUser(id);},
    [&user_manager](const InetAddr &id){user_manager->DelUser(id);},
    [&user_manager](int sockfd,const std::string &message){user_manager->Router(sockfd,message);});
    
    server->Init();

    server->Start();
    return 0;
}